import { _decorator, CCBoolean, CCInteger, Component, renderer, Sprite, tween, v3, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('shadowCtl')
export class shadowCtl extends Component {

    _cutMt: renderer.MaterialInstance = null;
    _initExAngle: number = 0;
    @property(CCInteger) angle: number = 0
    @property(CCBoolean) asyncAngle: boolean = false

    start() {
        this._cutMt = this.getComponent(Sprite).getMaterialInstance(0)
        this._initExAngle = this.node.eulerAngles.z

        tween(this.node).by(10, { eulerAngles: v3(0, 0, this.angle) })
            .repeatForever()
            .start()
    }

    _curEulerAngle: Vec3 = v3()
    update(deltaTime: number) {
        //同步旋转信息(后续研究下从矩阵获取旋转信息)
        if (this.asyncAngle) {
            this._curEulerAngle = this.node.eulerAngles
            this._cutMt.setProperty("eulerAngle", this._initExAngle * 0.5 - this._curEulerAngle.z)
        }

    }
}


